package com.bridgeintelligent.tag.engine.es.base;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author JackCheung
 * @date 2021/6/2 4:20 下午.
 * description:
 */
@Slf4j
@Aspect
@Component
@AllArgsConstructor
public class EsExceptionAcpect {

    private final ESQueryUtils esQueryUtils;

    @Pointcut("execution(public * com.bridgeintelligent.tag.engine.mvc..*.*(..))")
    public void exception() {
    }

    @Around("exception()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        try {
            return pjp.proceed();
        } catch (IllegalStateException e) {
            log.error("\n\n--------------es查询发生异常", e);
            esQueryUtils.restartConnect();
            throw e;
        }
    }
}
